package humanMirror.model.human;

/**
 * This class is used for storing an information about organ.
 *
 * @author Vladimir Vyshko
 * @author Anton Samarsky
 * @author Dima Glushko
 * @version 2.02 25 jul 2012
 */
public class OrganInfo {

    private OneOrganInfo organParameters[];

    public OrganInfo() {
        organParameters = new OneOrganInfo[SomeConstants.COUNT_OF_ORGANS];
        for (int i = 0; i < organParameters.length; i++) {
            organParameters[i] = new OneOrganInfo();
        }
    }

    /**
     * This method checks the correctness of the arguments.
     *
     * @param organ is id of organ.
     * @param param is id of parameter of organ organ.
     * @return "true" if any of arguments is wrong.
     */
    private boolean wrongArguments(int organ, int param) {
        if (organ >= SomeConstants.COUNT_OF_ORGANS || organ < 0)
            return true;
        return param >= SomeConstants.MAX_COUNT_OF_PARAMS || param < 0;
    }

    /**
     * This method is used for setting some parameter of organ.
     *
     * @param organ       is id of organ.
     * @param paramNumber is id of parameter of organ organ.
     * @param value       is value of effect which you want to set.
     * @throws IllegalArgumentException if it was specified nonexistent organ or parameter.
     */
    public void setParameter(int organ, int paramNumber, int value) {
        if (this.wrongArguments(organ, paramNumber))
            throw new IllegalArgumentException("It was specified wrong organ or parameter!");
        organParameters[organ].set(paramNumber, value);
    }

    /**
     * This method is used for getting some parameter of organ.
     *
     * @param organ       is id of organ.
     * @param paramNumber is id of parameter of organ organ.
     * @return value of effect.
     * @throws IllegalArgumentException if it was specified nonexistent organ or parameter.
     */
    int getParameter(int organ, int paramNumber) {
        if (this.wrongArguments(organ, paramNumber))
            throw new IllegalArgumentException("It was specified wrong organ or parameter!");
        return organParameters[organ].get(paramNumber);
    }

    /**
     * This method is used to add each element of object values to each element of current object
     *
     * @param values object whose elements are added to current object
     */
    public void addParameters(OrganInfo values) {
        for (int currentOrgan = 0; currentOrgan < SomeConstants.COUNT_OF_ORGANS; currentOrgan++)
            for (int currentParam = 0; currentParam < SomeConstants.MAX_COUNT_OF_PARAMS; currentParam++)
                organParameters[currentOrgan].add(currentParam, values.getParameter(currentOrgan, currentParam));
    }

    public OneOrganInfo getOneOrganParameters(int organ) {
        return organParameters[organ].copy();
    }

    public void getOneOrganParameters(int organ, OneOrganInfo params) {
        for (int currentParam = 0; currentParam < organParameters[organ].getCountOfParameters(); currentParam++) {
            organParameters[organ].set(currentParam, params.get(currentParam));
        }
    }
}
